/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\defgroup   avrcp_profile
\brief      The events sent from the avrcp profile using the Event Bus
*/

#include "avrcp_profile_event_send.h"
#include "avrcp_profile_channel_event_spec.h"

#include "event_bus_publish.h"

#include <logging.h>


static void avrcpProfile_EventBusSend(avrcp_profile_event_t event, void * data, uint16 data_size)
{
    EventBus_Publish(EVENT_BUS_CHANNEL_AVRCP_PROFILE, event, data, data_size);
}

void AvrcpProfile_EventSendAvrcpConnected(avInstanceTaskData *theInst)
{
    DEBUG_LOG("AvrcpProfile_EventSendAvrcpConnected");
    
    avrcp_profile_event_connected_t event = {0};
    event.addr = theInst->bd_addr;
    avrcpProfile_EventBusSend(avrcp_profile_event_connected, &event, sizeof(avrcp_profile_event_connected_t));
}

void AvrcpProfile_EventSendAvrcpDisconnected(avInstanceTaskData *theInst)
{
    DEBUG_LOG("AvrcpProfile_EventSendAvrcpDisconnected");
    
    avrcp_profile_event_disconnected_t event = {0};
    event.addr = theInst->bd_addr;
    avrcpProfile_EventBusSend(avrcp_profile_event_disconnected, &event, sizeof(avrcp_profile_event_disconnected_t));
}

void AvrcpProfile_EventSendAvrcpRemoteAbsoluteVolSupport(avInstanceTaskData *theInst, bool supported)
{
    DEBUG_LOG("AvrcpProfile_EventSendAvrcpRemoteAbsoluteVolSupport supported=%d", supported);
    
    avrcp_profile_event_remote_device_absolute_vol_support_t event = {0};
    event.addr = theInst->bd_addr;
    event.supported = supported;
    avrcpProfile_EventBusSend(avrcp_profile_event_remote_device_absolute_vol_support, &event, sizeof(avrcp_profile_event_remote_device_absolute_vol_support_t));
}

/* TODO When is this used, do we only know based on RegisterNotification? */
void AvrcpProfile_EventSendAvrcpRemotePlaybackStatusSupported(avInstanceTaskData *theInst, bool supported)
{
    DEBUG_LOG("AvrcpProfile_EventSendAvrcpRemotePlaybackStatusSupported supported=%d", supported);
    
    avrcp_profile_event_remote_device_playback_status_support_t event = {0};
    event.addr = theInst->bd_addr;
    event.supported = supported;
    avrcpProfile_EventBusSend(avrcp_profile_event_remote_device_playback_status_support, &event, sizeof(avrcp_profile_event_remote_device_playback_status_support_t));
}

void AvrcpProfile_EventSendAvrcpRemotePlaybackStatusChanged(avInstanceTaskData *theInst, uint8 playback_status)
{
    DEBUG_LOG("AvrcpProfile_EventSendAvrcpRemotePlaybackStatusChanged playback_status=%d", playback_status);
    
    avrcp_profile_event_remote_device_playback_status_changed_t event = {0};
    event.addr = theInst->bd_addr;
    event.playback_status = playback_status;
    avrcpProfile_EventBusSend(avrcp_profile_event_remote_device_playback_status_changed, &event, sizeof(avrcp_profile_event_remote_device_playback_status_changed_t));
}

void AvrcpProfile_EventSendAvrcpRemoteAbsoluteVolUpdate(avInstanceTaskData *theInst, uint8 volume)
{
    DEBUG_LOG("AvrcpProfile_EventSendAvrcpRemoteAbsoluteVolUpdate volume=%d", volume);
    
    avrcp_profile_event_remote_device_absolute_vol_update_t event = {0};
    event.addr = theInst->bd_addr;
    event.volume = volume;
    avrcpProfile_EventBusSend(avrcp_profile_event_remote_device_absolute_vol_update, &event, sizeof(avrcp_profile_event_remote_device_absolute_vol_update_t));
}

